﻿package mortal.game.view.guildNew
{
    import __AS3__.vec.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.guide.*;
    import mortal.game.view.copy.QuestionCopy.data.*;
    import mortal.game.view.guildNew.WareHourse.*;
    import mortal.game.view.guildNew.activity.*;
    import mortal.game.view.guildNew.building.*;
    import mortal.game.view.guildNew.data.*;
    import mortal.game.view.guildNew.info.*;
    import mortal.game.view.guildNew.manor.*;
    import mortal.game.view.guildNew.member.*;
    import mortal.game.view.guildNew.mercenary.*;
    import mortal.game.view.guildNew.other.*;
    import mortal.game.view.guildNew.otherGuild.*;
    import mortal.game.view.guildNew.shop.*;
    import mortal.game.view.guildNew.skill.*;
    import mortal.game.view.wizard.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuildNewModule extends BaseWindow
    {
        public var curPanel:GSprite = null;
        private var _tabBar:GTabarNew = null;
        private var _tabData:Array;
        private var _panelClassList:Vector.<Class> = null;
        private var _hintPanel:GuildNewHintPanel;
        private var _selIndex:String = null;
        private var _isLoad:Boolean = false;
        private var _curIndex:int = -1;
        public static const Info:String = "m1";
        public static const Member:String = "m2";
        public static const Building:String = "m3";
        public static const Manor:String = "m4";
        public static const WareH:String = "m5";
        public static const Shop:String = "m6";
        public static const Skill:String = "m7";
        public static const Active:String = "m8";
        public static const Mercenary:String = "m9";

        public function GuildNewModule(param1:ILayer = null)
        {
            this._tabData = [];
            super(param1);
            setSize(758, 538);
            title = "" + Language.getString(71687);
            titleHeight = 60;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.guildNew, this.onResLoad);
            return;
        }// end function

        private function onResLoad() : void
        {
            this._isLoad = true;
            this._tabBar = UIFactory.gTabBarNew(2, 32, this._tabData, 755, 500, 65, 26, this, this.onTabBarChange);
            this.updateTab();
            this._tabBar.selectedIndex = 0;
            if (this._selIndex != null)
            {
                this.selectedIndex = this._selIndex;
            }
            this.onTabBarChange();
            this._hintPanel = UIFactory.getUICompoment(GuildNewHintPanel, 0, 0, this);
            this.updateHintAll();
            AutoGuideRedPoint3.instance.unShineMainBtn(ModuleType.Guild);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._isLoad == false)
            {
                return;
            }
            this._isLoad = false;
            this._hintPanel = null;
            this._curIndex = -1;
            this._selIndex = null;
            this._tabBar.dispose(param1);
            this._tabBar = null;
            this._tabData.length = 0;
            if (this.curPanel)
            {
                this.curPanel.dispose(param1);
                this.curPanel = null;
            }
            return;
        }// end function

        public function updateTab() : void
        {
            this._tabData = [];
            this._tabData.push({name:"m1", label:"" + Language.getString(71688)});
            this._tabData.push({name:"m2", label:"" + Language.getString(71689)});
            this._tabData.push({name:"m3", label:"" + Language.getString(71690)});
            this._tabData.push({name:"m4", label:"" + Language.getString(71691)});
            this._tabData.push({name:"m5", label:"" + Language.getString(71692)});
            this._tabData.push({name:"m6", label:"" + Language.getString(71693)});
            this._tabData.push({name:"m7", label:"" + Language.getString(71694)});
            this._tabData.push({name:"m8", label:"" + Language.getString(71695)});
            if (LevelCheckUtil.isLevelEnougth(LevelCheckUtil.mercenary))
            {
                this._tabData.push({name:"m9", label:"" + Language.getString(71696)});
            }
            this._tabBar.dataProvider = this._tabData;
            return;
        }// end function

        public function set selectedIndex(param1:String) : void
        {
            var _loc_3:int = 0;
            this._selIndex = param1;
            if (this._isLoad == false)
            {
                return;
            }
            var _loc_2:* = this._tabBar.dataProvider;
            this._tabBar.selectedIndex = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                if (_loc_2[_loc_3].name == param1)
                {
                    this._tabBar.selectedIndex = _loc_3;
                    this.onTabBarChange(null);
                    return;
                }
                _loc_3++;
            }
            this._tabBar.selectedIndex = 0;
            this.onTabBarChange(null);
            return;
        }// end function

        private function onTabBarChange(event:Event = null) : void
        {
            if (AutoGuideController._guidingMainId == 25)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStopCurStep, [25]));
            }
            if (this._curIndex != -1 && this._curIndex == this._tabBar.selectedIndex)
            {
                return;
            }
            this._curIndex = this._tabBar.selectedIndex;
            if (this.curPanel)
            {
                this.curPanel.dispose(true);
                this.curPanel = null;
            }
            this.updatePanel();
            if (this.curPanel is GuildNewMemberPanel)
            {
                (this.curPanel as GuildNewMemberPanel).listType = 0;
                return;
            }
            return;
        }// end function

        private function updatePanel() : void
        {
            var _loc_1:* = this._tabBar.dataProvider[this._tabBar.selectedIndex].name;
            switch(_loc_1)
            {
                case Info:
                {
                    this.addInfoPanel();
                    break;
                }
                case Member:
                {
                    this.addMemberPanel();
                    break;
                }
                case Building:
                {
                    this.addBuildingPanel();
                    break;
                }
                case Manor:
                {
                    this.addGuildListPanel();
                    break;
                }
                case WareH:
                {
                    this.addWareHoursePanel();
                    break;
                }
                case Shop:
                {
                    this.addShopPanel();
                    break;
                }
                case Skill:
                {
                    this.addSkillPanel();
                    break;
                }
                case Active:
                {
                    this.addActivityPanel();
                    break;
                }
                case Mercenary:
                {
                    this.addMercenaryPanel();
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function addInfoPanel() : GuildNewInfoPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewInfoPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewInfoPanel;
        }// end function

        private function addMemberPanel() : GuildNewMemberPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewMemberPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewMemberPanel;
        }// end function

        private function addBuildingPanel() : GuildNewBuildingPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewBuildingPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewBuildingPanel;
        }// end function

        private function addManorPanel() : GuildNewManorPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewManorPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewManorPanel;
        }// end function

        private function addGuildListPanel() : GuildNewOtherPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewOtherPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewOtherPanel;
        }// end function

        private function addWareHoursePanel() : GuildNewWareHPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewWareHPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewWareHPanel;
        }// end function

        private function addShopPanel() : GuildNewShopPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewShopPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewShopPanel;
        }// end function

        private function addSkillPanel() : GuildNewSkillPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewSkillPanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewSkillPanel;
        }// end function

        private function addActivityPanel() : GuildNewActivePanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewActivePanel);
            this.curPanel.x = 9;
            this.curPanel.y = 65;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewActivePanel;
        }// end function

        private function addMercenaryPanel() : GuildNewMercenaryPanel
        {
            this.curPanel = UICompomentPool.getUICompoment(GuildNewMercenaryPanel);
            this.curPanel.x = 5;
            this.curPanel.y = 55;
            this.addChild(this.curPanel);
            return this.curPanel as GuildNewMercenaryPanel;
        }// end function

        public function update(param1:Class = null) : void
        {
            if (this.curPanel == null)
            {
                return;
            }
            if (this.curPanel.visible == false)
            {
                return;
            }
            if (param1 == null || this.curPanel is param1)
            {
                if (this.curPanel.isDisposed == false)
                {
                    var _loc_2:* = this.curPanel;
                    _loc_2.this.curPanel["update"]();
                }
            }
            this.updateApplyToJoinLabel();
            return;
        }// end function

        public function changeTab(param1:int) : void
        {
            this._tabBar.selectedIndex = param1;
            this.onTabBarChange(null);
            return;
        }// end function

        private function updateHintAll() : void
        {
            if (this._hintPanel)
            {
                this._hintPanel.updateApplyLabel();
                this._hintPanel.updateSkillLabel();
                this._hintPanel.updateApplyToJoinLabel();
            }
            return;
        }// end function

        public function updateApplyToJoinLabel() : void
        {
            if (this._hintPanel)
            {
                this._hintPanel.updateApplyToJoinLabel();
            }
            return;
        }// end function

        public function updateApplyLabel() : void
        {
            if (this._hintPanel)
            {
                this._hintPanel.updateApplyLabel();
            }
            return;
        }// end function

        public function updateSkillLabel() : void
        {
            if (this._hintPanel)
            {
                this._hintPanel.updateSkillLabel();
            }
            return;
        }// end function

        public function updateFruitsLabel(param1:Boolean) : void
        {
            if (this._hintPanel)
            {
                this._hintPanel.hasOtherFruits = param1;
            }
            return;
        }// end function

    }
}
